package me.itsoo.artemis.framework.core.tuple;

import lombok.AccessLevel;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * SimplePair
 *
 * @param <K> Key type
 * @param <V> Value type
 * @author zxy
 * @version 0.0.1
 * @since 2023/5/10
 */
@Data
public class SimplePair<K, V> implements Pair<K, V> {

    private static final SimplePair<?, ?> EMPTY = new EmptySimplePair();

    private K key;

    private V value;

    public static <K, V> SimplePair<K, V> create(K key, V value) {
        final SimplePair<K, V> result = new SimplePair<>();
        result.setKey(key);
        result.setValue(value);
        return result;
    }

    @SuppressWarnings("unchecked")
    public static <K, V> SimplePair<K, V> empty() {
        return (SimplePair<K, V>) EMPTY;
    }

    /**
     * EmptySimplePair
     */
    @NoArgsConstructor(access = AccessLevel.PRIVATE)
    private static class EmptySimplePair extends SimplePair<Object, Object> {

        @Override
        public void setKey(Object key) {
            super.setKey(null);
        }

        @Override
        public void setValue(Object value) {
            super.setValue(null);
        }

        @Override
        public Object getKey() {
            return null;
        }

        @Override
        public Object getValue() {
            return null;
        }
    }
}
